import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class POIExpExcel_2007
{

	public static void main(String[] args)
	{
		String[] title = {"name","gender","age"};
		
		//创建EXCEL工作薄  
		//(1) ---> XSSF
		XSSFWorkbook workbook = new XSSFWorkbook();
		
		//(2) -> ''
		//创建sheet
		Sheet sheet = workbook.createSheet();
		
		//创建第一行
		Row row = sheet.createRow(0);
		Cell cell = null;
		//设置标题
		for(int i = 0; i < title.length; i++)
		{
			cell = row.createCell(i);
			cell.setCellValue(title[i]);;
		}
		for(int i = 1;i<10; i++)
		{
			Row nextrow = sheet.createRow(i);
			Cell cell2 = nextrow.createCell(0);
			cell2.setCellValue("user"+i);
			
			cell2 = nextrow.createCell(1);
			cell2.setCellValue("男");
			
			cell2 = nextrow.createCell(2);
			cell2.setCellValue(String.valueOf(10+i));
		}
		
		//创建一个文件
		File file = new File("POI_excel.xlsx");
		try
		{
			file.createNewFile();
			FileOutputStream stream = FileUtils.openOutputStream(file);
			workbook.write(stream);
			stream.close();
			
			workbook.close();
		} 
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
